<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.util.Time" %>
<%@ include file="top.jsp" %>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>新建任务</title>

</head>
<body>
	
	<%
		List<Employee> workers=(List<Employee>)session.getAttribute("workersp");
	 %>

	<div class="container well" style="width:800px">
		<h1>新建任务</h1>
		
		
			<form action="addtask.jspx" method="post" id="form" class="form-horizontal well">
						
						<div class="form-inline">
							<label>任务名称</label><br>
							<input style="height:30px" type="text" id="input01" class="input-xlarge" placeholder="请输入任务名称" name = "taskName">
							<span style="color:red" id="input01_msg"></span>
						</div>
						
						<br /><br />
						<label>任务描述</label>
						<textarea rows="3" id="input02" class="span7"  placeholder="请输入任务的描述" name = "taskDesc"></textarea>
						<span style="color:red" id="input02_msg"></span>
						<br /><br />
						<label>负责人</label>
						<select id="input03" name="taskAdmin">
							<option value="">-请选择任务负责人-</option>
							<%
								for(Employee e:workers){
							 %>
							<option value="<%=e.getId()%>"><%=e.getUsername() %></option>
							<%
								}
							 %>
						</select>
						<span style="color:red" id="input03_msg"></span>
						<br /><br />
						<label>任务状态</label>
						<input style="height:30px" type="text" id="input04" class="input-xlarge disabled" disabled="" value="新任务" name = "taskName">
						<span style="color:red" id="input04_msg"></span>
						<br /><br />
						<label>任务级别</label>
						<select id="input05" name="taskLevel">
							<option value="">-请选择任务级别-</option>
							<option value="1">重要紧急</option>
							<option value="2">重要不紧急</option>
							<option value="3">紧急不重要</option>
							<option value="4">不紧急不重要</option>
						</select>
						<span style="color:red" id="input05_msg"></span>
						<br /><br />
						<label>任务开始日期</label>
						<input style="height:30px" type="text" id="input06" class="input-xlarge" placeholder="请输入任务开始时间" name = "starttime">
						<span style="color:red" id="input06_msg"></span>
						<div><small>示例样式 &nbsp; 如：<%=Time.getDay() %></small></div>		
						<br>
						
						<label>任务结束日期</label>
						<input style="height:30px" type="text" id="input07" class="input-xlarge" placeholder="请输入任务结束时间" name = "endtime">
						<span style="color:red" id="input07_msg"></span>
						<div><small>示例样式 &nbsp; 如：<%=Time.getDay() %></small></div>		
						
						<div class="form-actions">
							<button class="btn btn-primary" type="submit">保存任务</button>
							<a class="btn" href="task.jspx">取消</a>
						</div>
						
			</form>
		</div>
	</div>
	<script type="text/javascript">
	
	    var reg = /^\d{2,4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$/;
	  
	
document.getElementById("form").onsubmit=function(){
			
			var input01 = document.getElementById("input01").value;
			var input02 = document.getElementById("input02").value;
			var input03 = document.getElementById("input03").value;
			var input04 = document.getElementById("input04").value;
			var input05 = document.getElementById("input05").value;
			var input06 = document.getElementById("input06").value;
			var input07 = document.getElementById("input07").value;
		
			if(input01.trim() == "") {
				
				document.getElementById("input01_msg").innerHTML = "请输入任务名称";
				document.getElementById("input01").focus();
				return false;
			}
			if(input02.trim() == "") {
				
				document.getElementById("input02_msg").innerHTML = "请输入任务描述";
				document.getElementById("input02").focus();
				return false;
			}
			if(input03.trim() == "") {
				
				document.getElementById("input03_msg").innerHTML = "请选择任务负责人";
				document.getElementById("input03").focus();
				return false;
			}
			if(input04.trim() == "") {
				
				document.getElementById("input04_msg").innerHTML = "请选择任务状态";
				document.getElementById("input04").focus();
				return false;
			}
			if(input05.trim() == "") {
				
				document.getElementById("input05_msg").innerHTML = "请选择任务级别";
				document.getElementById("input05").focus();
				return false;
			}
			if(input06.trim() == "") {
				
				document.getElementById("input06_msg").innerHTML = "请输入任务开始时间";
				document.getElementById("input06").focus();
				return false;
			}else{
				if(!reg.test(input06)){
					document.getElementById("input06_msg").innerHTML = "请按示例样式输入";
					document.getElementById("input06").focus();
					return false;
				}
			}
			if(input07.trim() == "") {
				
				document.getElementById("input07_msg").innerHTML = "请输入任务结束时间";
				document.getElementById("input07").focus();
				return false;
			}else{
				if(!reg.test(input07)){
					document.getElementById("input07_msg").innerHTML = "请按示例样式输入";
					document.getElementById("input07").focus();
					return false;
				}
			}
			
			  function DateDemo(){
				   var d,m, s = "";           // 声明变量。
				   d = new Date();                           // 创建 Date 对象。
				   s += d.getFullYear()+"-";
				   m = (d.getMonth() +1 );
				   if(m < 10){
					   m = "0"+m;
				   }
				   s += m+"-";
				   s += d.getDate();
				   
				   return(s);                                // 返回日期。
				   
				};
				
				
			var date=DateDemo();
			
			if(date>input06){
				document.getElementById("input06_msg").innerHTML = "任务开始时间不得早于今天";
				document.getElementById("input06").focus();
				return false;
			}
			if(input06>input07){
				document.getElementById("input07_msg").innerHTML = "任务结束时间不得早于任务开始时间";
				document.getElementById("input07").focus();
				return false;
			}
			
		};
	    
		document.getElementById("input01").onblur = function(){
		
			var input01 = document.getElementById("input01").value;
			
			if(input01.trim() == "") {
				document.getElementById("input01").value = "";
				document.getElementById("input01_msg").innerHTML = "请输入任务名称";
				document.getElementById("input01").focus();
			}else{
				document.getElementById("input01_msg").innerHTML = "";
			}
		};
		document.getElementById("input02").onblur = function(){
		
			var input02 = document.getElementById("input02").value;
			if(input02.trim() == "") {
				document.getElementById("input02").value = "";
				document.getElementById("input02_msg").innerHTML = "请输入任务描述";
				document.getElementById("input02").focus();
			}else{
				document.getElementById("input02_msg").innerHTML = "";
			}
		};
		document.getElementById("input03").onblur = function(){
		
			var input03 = document.getElementById("input03").value;
			if(input03.trim() == "") {
				document.getElementById("input03").value = "";
				document.getElementById("input03_msg").innerHTML = "请选择任务负责人";
				document.getElementById("input03").focus();
			}else{
				document.getElementById("input03_msg").innerHTML = "";
			}
		};
		document.getElementById("input04").onblur = function(){
		
			var input04 = document.getElementById("input04").value;
			if(input04.trim() == "") {
				document.getElementById("input04").value = "";
				document.getElementById("input04_msg").innerHTML = "请选择任务状态";
				document.getElementById("input04").focus();
			}else{
				document.getElementById("input04_msg").innerHTML = "";
			}
		};
		document.getElementById("input05").onblur = function(){
		
			var input05 = document.getElementById("input05").value;
			if(input05.trim() == "") {
				document.getElementById("input05").value = "";
				document.getElementById("input05_msg").innerHTML = "请选择任务描述";
				document.getElementById("input05").focus();
			}else{
				document.getElementById("input05_msg").innerHTML = "";
			}
		};
		document.getElementById("input06").onblur = function(){
			
			var input06 = document.getElementById("input06").value;
			if(input06.trim() == "") {
				document.getElementById("input06").value = "";
				document.getElementById("input06_msg").innerHTML = "请选择任务开始时间";
				document.getElementById("input06").focus();
			}else{
				document.getElementById("input06_msg").innerHTML = "";
			}
		};
		document.getElementById("input07").onblur = function(){
			
			var input07 = document.getElementById("input07").value;
			if(input07.trim() == "") {
				document.getElementById("input07").value = "";
				document.getElementById("input07_msg").innerHTML = "请选择任务结束时间";
				document.getElementById("input07").focus();
			}else{
				document.getElementById("input07_msg").innerHTML = "";
			}
		};
		
		
		document.getElementById("input01").onkeydown = function(){
			
			document.getElementById("input01_msg").innerHTML = "";
		};
		document.getElementById("input02").onkeydown = function(){
			document.getElementById("input02_msg").innerHTML = "";
		};
		document.getElementById("input03").onchange = function(){
			
			document.getElementById("input03_msg").innerHTML = "";
		};
		document.getElementById("input04").onchange = function(){
			
			document.getElementById("input04_msg").innerHTML = "";
		};
		document.getElementById("input05").onchange = function(){
			
			document.getElementById("input05_msg").innerHTML = "";
		};
		document.getElementById("input06").onkeydown = function(){
					
			document.getElementById("input06_msg").innerHTML = "";
		};
		document.getElementById("input07").onkeydown = function(){
					
			document.getElementById("input07_msg").innerHTML = "";
		};
		
    		
    	
	</script>
</body>
</html>
